import React, { useReducer } from 'react';

// 2s 之后返回双倍的值
function doubleAfter2seconds(num) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve(2 * num);
    }, 1000);
  });
}

export default {
  state: {
    count: 0,
  },

  reducers: {
    /*打开系统弹出窗口*/
    incrE2(state, action) {
      console.log('incrE2')
      debugger
      return { count: state.count + 1, payload: action.payload };
    },
    decrE2(state, action) {
      return { count: state.count - 1 };
    },
    reset(state, action) {
      return { ...state, count: 0 };
    },
  },
  effects: {
    async incr2(action, { call, put }) {
      put({ type: 'incrE2', payload: action.payload });
      console.log('2222222');
      let result = await doubleAfter2seconds(30);
      console.log(result);
      console.log('3333');
      // call({type: 'decr', payload: action.payload})
    },
    async decr2(action, { call, put }) {
      put({ type: 'decrE2', payload: '' });
      let result = await doubleAfter2seconds(30);
      console.log(result);
      // call({type: 'incr', payload: action.payload})

    },
  },
};
